package com.itheima.a01myexception;

public class ExceptionDemo12 {
    public static void main(String[] args) {


        int[] arr = null;
        int num = 0;
        try {
            num = getMax(arr);
        } catch (NullPointerException e) {
            System.out.println("空指针异常");
        } catch (ArrayIndexOutOfBoundsException e){
            System.out.println("索引越界异常");
        }
        System.out.println(num);
    }

    private static int getMax(int[] arr) /*throws NullPointerException,ArrayIndexOutOfBoundsException*/ {
        if(arr == null){
            throw new NullPointerException();
        }
        if(arr.length == 0){
            throw new ArrayIndexOutOfBoundsException();
        }
        int ret = arr[0];
        for(int i=1;i<arr.length;i++){
            if(arr[i] > ret){
                ret = arr[i];
            }
        }
        return ret;
    }
}
